#ifndef PAGESWIDGET_H
#define PAGESWIDGET_H

#include <QWidget>

#include "dragabletab.h"

#include <QHBoxLayout>

namespace Ui {
class PagesWidget;
}

class DroppableWidget;
class TabsScrollArea;

/*
    继承了 QWidget GUI类
    整体功能:
        内置了tabsScrollArea和所有tab的content，作为展示载体存在
    具体功能：
        1、承接了tabsScrollArea相关功能，并增加显示content的功能
*/

class PagesWidget : public QWidget
{
    Q_OBJECT

public:
    explicit PagesWidget(QWidget *parent = nullptr);
    ~PagesWidget() override;

    TabsScrollArea* GetTabsScrollArea() const;

    std::pair<int, int> Id() const;
    void SetId(int dId, int pId);
    void SetParentDroppableWidget(DroppableWidget* droppableWidget);
    DroppableWidget* ParentDroppableWidget();

    std::pair<DragableTab*, QWidget*> CurrentPage() const;


    void AddPage(DragableTab *tab, QWidget *content);
    void AddPage(QString titleLabel, QWidget *content, DragableTab::TabType tabType=DragableTab::TabType::DEFAULT);
    void InsertPage(int index, DragableTab *tab, QWidget *content);
    void InsertPage(int index, QString titleLabel, QWidget *content);

    std::pair<DragableTab*, QWidget*> RemovePage(int index);
    std::pair<DragableTab*, QWidget*> RemovePage(const DragableTab *tab);


    void SwapPage(const int from, const int to);
    std::pair<DragableTab*, QWidget*> ReplacePage(DragableTab* fromTab, DragableTab* toTab, QWidget* toContent);
protected:
    void closeEvent(QCloseEvent *event) override;

private:
    void ConnectAll();


    Ui::PagesWidget *ui;
    TabsScrollArea* mTabsScrollArea {nullptr};
    DroppableWidget* mDroppableWidget {nullptr};

private slots:
    void CloseTabFromButton();

signals:
    void closed();

    friend class DropManager;
};

#endif // PAGESWIDGET_H
